package com.zzf.eduservice.controller;


import com.zzf.commonutils.R;
import com.zzf.eduservice.entity.EduSubject;
import com.zzf.eduservice.entity.subject.OneSubject;
import com.zzf.eduservice.listener.SubjectExcelListener;
import com.zzf.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-04-05
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
@Api(description = "课程分类管理")
public class EduSubjectController {
    @Autowired
    private EduSubjectService subjectService;

    //添加课程分类
    //获取到上传的表格文件,把文件内容读取出来
    @ApiOperation(value = "上传Excel文件生成课程分类")
    @PostMapping("addSubject")
    public R addSubject(@ApiParam(name = "file", value = "课程分类Excel文件", required = true)
                                    MultipartFile file){
        //上传过来的文件
        subjectService.saveSubject(file,subjectService);

        return R.ok();
    }

    @ApiOperation(value = "获取所有课程分类数据")
    @GetMapping("getAllSubject")
    public R getAllSubject(){
        List<OneSubject> list = subjectService.getAllOneTwoSubject();
        return R.ok().data("list",list);
    }
}

